package com.snail.snailvr.mvp.presenter;

import com.snail.snailvr.mvp.views.BaseView;
import com.snail.snailvr.network.IFSResponse;
import com.snail.snailvr.utils.LogUtils;

/**
 * 接收数据回调
 * Created by sunxiangyao on 15/4/5.
 */
abstract class Presenter implements IFSResponse {
    /**
     * 初始化MVPView
     */
    public abstract BaseView getMvpView();

    public abstract void success(Object o);

    public abstract void loadData();//请求网络数据

    @Override
    public void onSuccess(Object o) {
        if (getMvpView() != null) {
            if (o != null && getMvpView().getContext() != null) {
                success(o);
            } else if (o == null) {
                getMvpView().showError();
                LogUtils.d("result=null");
            }
            getMvpView().hideLoading();
        }
    }

    @Override
    public void onNetWorkError() {
        if (getMvpView() != null) {
            error();
        }
    }

    @Override
    public void onServerError() {
        if (getMvpView() != null) {
            error();
        }
    }

    private void error() {
        if (getMvpView() != null)
            getMvpView().showError();
    }

}
